package com.example.springboot.dao;


import com.example.springboot.entity.City;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by tang on 2017/12/4.
 */
@Mapper
public interface CityMapper {

    @Results(id = "city", value = {
            @Result(property = "id", column = "id"),
            @Result(property = "provinceId", column = "province_id"),
            @Result(property = "cityName", column = "city_name"),
            @Result(property = "description", column = "description"),

    })
    @Select("select * from city where city_name=#{cityName}")
    public City findByName(@Param("cityName") String cityName);


    @Select("select * from city where province_id=#{id}")
    @ResultMap("city")
    public City findByProvinceId(Integer id);

    @Select("select * from city ")
    @ResultMap("city")
    public List<City> findAll();

    @Update("update city set city_name=#{cityName},province_id=#{provinceId},description=#{description} where id=#{id}")
    public void updateCity(City city);

    @Insert("insert into city(city_name,province_id,description) values(#{cityName},#{provinceId},#{description})")
    public void addCity(City city);

    @Delete("delete from city where id=#{id}")
    public void deleteCity(int id);
}
